package com.seraph.zys.dao.impl;

import com.seraph.bi.suite.support.domain.pagination.PageBox;
import com.seraph.bi.suite.support.domain.pagination.PageObject;
import com.seraph.zys.dao.ScOrgSeqDAO;
import com.seraph.zys.dao.domain.ScOrgSeq;
import com.seraph.zys.dao.domain.ScOrgSeqExample;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class ScOrgSeqDAOImpl extends SqlMapClientDaoSupport implements ScOrgSeqDAO {

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public ScOrgSeqDAOImpl() {
        super();
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public void insert(ScOrgSeq record) {
        getSqlMapClientTemplate().insert("sc_org_seq.abatorgenerated_insert", record);
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int updateByPrimaryKey(ScOrgSeq record) {
        int rows = getSqlMapClientTemplate().update("sc_org_seq.abatorgenerated_updateByPrimaryKey", record);
        return rows;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int updateByPrimaryKeySelective(ScOrgSeq record) {
        int rows = getSqlMapClientTemplate().update("sc_org_seq.abatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public List selectByExample(ScOrgSeqExample example, String orderByClause) {
        Map parms = getExampleParms(example);
        if (orderByClause != null) {
            parms.put("ABATOR_ORDER_BY_CLAUSE", orderByClause);
        }
        List list = getSqlMapClientTemplate().queryForList("sc_org_seq.abatorgenerated_selectByExample", parms);
        return list;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public List selectByExample(ScOrgSeqExample example) {
        return selectByExample(example, null);
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public ScOrgSeq selectByPrimaryKey(String orgCode) {
        ScOrgSeq key = new ScOrgSeq();
        key.setOrgCode(orgCode);
        ScOrgSeq record = (ScOrgSeq) getSqlMapClientTemplate().queryForObject("sc_org_seq.abatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    public int getNextOrgCurrSeq(String orgCode) {
        ScOrgSeq key = new ScOrgSeq();
        key.setOrgCode(orgCode);
        ScOrgSeq record = (ScOrgSeq) getSqlMapClientTemplate().queryForObject("sc_org_seq.abatorgenerated_selectByPrimaryKey", key);       
        getSqlMapClientTemplate().update("sc_org_seq.abatorgenerated_updateCurrOrgSeq", key);
        return record.getCurSeq();
    }    
    
    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int deleteByExample(ScOrgSeqExample example) {
        int rows = getSqlMapClientTemplate().delete("sc_org_seq.abatorgenerated_deleteByExample", getExampleParms(example));
        return rows;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int deleteByPrimaryKey(String orgCode) {
        ScOrgSeq key = new ScOrgSeq();
        key.setOrgCode(orgCode);
        int rows = getSqlMapClientTemplate().delete("sc_org_seq.abatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    private Map getORG_CODEExampleParms(ScOrgSeqExample example) {
        Map parms = new HashMap();
        switch (example.getOrgCode_Indicator()) {
        case ScOrgSeqExample.EXAMPLE_NULL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_NULL", "Y");
            } else {
                parms.put("AND_ORG_CODE_NULL", "Y");
            }
            break;
        case ScOrgSeqExample.EXAMPLE_NOT_NULL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_NOT_NULL", "Y");
            } else {
                parms.put("AND_ORG_CODE_NOT_NULL", "Y");
            }
            break;
        case ScOrgSeqExample.EXAMPLE_EQUALS:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_EQUALS", "Y");
            } else {
                parms.put("AND_ORG_CODE_EQUALS", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_NOT_EQUALS:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_NOT_EQUALS", "Y");
            } else {
                parms.put("AND_ORG_CODE_NOT_EQUALS", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_GREATER_THAN:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_GT", "Y");
            } else {
                parms.put("AND_ORG_CODE_GT", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_GREATER_THAN_OR_EQUAL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_GE", "Y");
            } else {
                parms.put("AND_ORG_CODE_GE", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_LESS_THAN:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_LT", "Y");
            } else {
                parms.put("AND_ORG_CODE_LT", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_LESS_THAN_OR_EQUAL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_LE", "Y");
            } else {
                parms.put("AND_ORG_CODE_LE", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        case ScOrgSeqExample.EXAMPLE_LIKE:
            if (example.isCombineTypeOr()) {
                parms.put("OR_ORG_CODE_LIKE", "Y");
            } else {
                parms.put("AND_ORG_CODE_LIKE", "Y");
            }
            parms.put("orgCode", example.getOrgCode());
            break;
        }
        return parms;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    private Map getCUR_SEQExampleParms(ScOrgSeqExample example) {
        Map parms = new HashMap();
        switch (example.getCurSeq_Indicator()) {
        case ScOrgSeqExample.EXAMPLE_NULL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_NULL", "Y");
            } else {
                parms.put("AND_CUR_SEQ_NULL", "Y");
            }
            break;
        case ScOrgSeqExample.EXAMPLE_NOT_NULL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_NOT_NULL", "Y");
            } else {
                parms.put("AND_CUR_SEQ_NOT_NULL", "Y");
            }
            break;
        case ScOrgSeqExample.EXAMPLE_EQUALS:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_EQUALS", "Y");
            } else {
                parms.put("AND_CUR_SEQ_EQUALS", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        case ScOrgSeqExample.EXAMPLE_NOT_EQUALS:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_NOT_EQUALS", "Y");
            } else {
                parms.put("AND_CUR_SEQ_NOT_EQUALS", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        case ScOrgSeqExample.EXAMPLE_GREATER_THAN:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_GT", "Y");
            } else {
                parms.put("AND_CUR_SEQ_GT", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        case ScOrgSeqExample.EXAMPLE_GREATER_THAN_OR_EQUAL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_GE", "Y");
            } else {
                parms.put("AND_CUR_SEQ_GE", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        case ScOrgSeqExample.EXAMPLE_LESS_THAN:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_LT", "Y");
            } else {
                parms.put("AND_CUR_SEQ_LT", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        case ScOrgSeqExample.EXAMPLE_LESS_THAN_OR_EQUAL:
            if (example.isCombineTypeOr()) {
                parms.put("OR_CUR_SEQ_LE", "Y");
            } else {
                parms.put("AND_CUR_SEQ_LE", "Y");
            }
            parms.put("curSeq", example.getCurSeq());
            break;
        }
        return parms;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    private Map getExampleParms(ScOrgSeqExample example) {
        Map parms = new HashMap();
        parms.putAll(getORG_CODEExampleParms(example));
        parms.putAll(getCUR_SEQExampleParms(example));
        return parms;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int selectCountByExample(ScOrgSeqExample example) {
        Map parms = getExampleParms(example);
        int count = ((Integer)getSqlMapClientTemplate().queryForObject("sc_org_seq.abatorgenerated_selectCountByExample", parms)).intValue();
        return count;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public PageBox selectByExampleWithPaging(ScOrgSeqExample example, int pageSize, int pageNum, String orderByClause) {
        Map parms = getExampleParms(example);
        if (orderByClause != null) {
            parms.put("ABATOR_ORDER_BY_CLAUSE", orderByClause);
        }
        PageBox pageBox = new PageBox();
        PageObject pageObject = new PageObject();
        pageObject.setPageSize(pageSize);
        pageObject.setPageIndex(pageNum);
        int itemAmount = selectCountByExample(example);
        pageObject.setItemAmount(itemAmount);
        List pageList = null;
        if (pageObject.getBeginIndex() <= pageObject.getItemAmount()) {
            pageList = (getSqlMapClientTemplate().queryForList("sc_org_seq.abatorgenerated_selectByExample", parms, pageObject.getBeginIndex() - 1, pageSize));
        }
        pageBox.setPageObject(pageObject);
        pageBox.setPageList(pageList);
        return pageBox;
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public PageBox selectByExampleWithPaging(ScOrgSeqExample example, int pageSize, int pageNum) {
        return selectByExampleWithPaging(example, pageSize, pageNum, null);
    }

    /**
     * This method was generated by Abator for iBATIS.
     * This method corresponds to the database table sc_org_seq
     *
     * @abatorgenerated Wed Oct 19 14:49:27 CST 2011
     */
    public int updateByPrimaryKeyForCgs(ScOrgSeq record) {
        int rows = getSqlMapClientTemplate().update("sc_org_seq.abatorgenerated_updateByPrimaryKeyForCgs", record);
        return rows;
    }
}